package cache_server

import (
	"memCache/cache"
	"time"
)

type cacheServer struct {
	cache cache.Cache
}

func NewMemCache() *cacheServer {
	c := &cacheServer{
		cache: cache.NewMemCache(),
	}
	return c
}

func (c *cacheServer) SetMaxMemory(size string) bool {
	return c.cache.SetMaxMemory(size)
}

// 将value写入缓存
func (c *cacheServer) Set(key string, val interface{}, expire ...time.Duration) bool {
	tmpExpire := 0 * time.Second
	if len(expire) > 0 {
		tmpExpire = expire[0]
	}
	return c.cache.Set(key, val, tmpExpire)
}

// 根据key值获取value
func (c *cacheServer) Get(key string) (interface{}, bool) {
	return c.cache.Get(key)
}

// 删除key值
func (c *cacheServer) Del(key string) bool {
	return c.cache.Del(key)
}

// 判断key是否存在
func (c *cacheServer) Exists(key string) bool {
	return c.cache.Exists(key)
}

// 清空所有kye
func (c *cacheServer) Flush() bool {
	return c.cache.Flush()
}

// 获取缓存中所有key的数量
func (c *cacheServer) Keys() int64 {
	return c.cache.Keys()
}
